package notebook.client;



import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Saying implements EntryPoint {

	Notebook nb;
	LoginPanel lp;
	public void onModuleLoad() {
		RootPanel rootPanel = RootPanel.get();
		VerticalPanel vp = new VerticalPanel();
		rootPanel.setSize("100%", "100%");
		vp.add(getReadButton());
		vp.add(getWriteButton());
		vp.add(getManageButton());
		vp.add(getLoginButton());
		rootPanel.add(vp);
	}

	private Button getReadButton(){
		Button read = new Button("浏览笔记");
		read.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				if(nb==null) nb = new Notebook();
				hideAll();
				nb.showRead();
			}});
		return read;
	};
	
	private Button getWriteButton(){
		Button write = new Button("添加笔记");
		write.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				if(nb==null) nb = new Notebook();
				hideAll();
				nb.showWrite();
			}});
		return write;
	};
	
	private Button getManageButton(){
		Button read = new Button("整理笔记");
		read.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				if(nb==null) nb = new Notebook();
				hideAll();
				nb.show();
			}});
		return read;
	};
	
	private Button getLoginButton(){
		Button read = new Button("用户登录");
		read.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				if(lp==null) lp = new LoginPanel();
				hideAll();
				lp.showChoice();
			}});
		return read;
	};
	private void hideAll(){
		if(nb!=null)nb.hide();
		if(lp!=null)lp.hide();
	}
}
